#include "w2b.h"
#define MAXPATH 128

int main (int argc, char *argv[])
{
    FILE *pFile;
    char strPath[MAXPATH];
    WAV_CACHE *data = NULL;
    BMP4bit_CACHE *bmp = NULL;
    //DWORD w = 0;
    //LONG h = 0;
    //DWORD n = 0;

    if (2 == argc && (strlen(argv[1]) + 1 <= MAXPATH))
    {
        sprintf(strPath, "%s", argv[1]);
    }
    else
    {
        fflush(stdin);
        puts("Please input the .wav file name\n");
        scanf("%[^\n]", strPath);
        fflush(stdin);
        strPath[MAXPATH - 1] = '\0';
    }
	pFile = fopen(strPath, "rb");
	if (pFile != NULL)
	{
		puts("File open success\n");
	}
	else
	{
		return err(FileErr);
	}

    data = cacheWaveFile(strPath);//缓存音频
    fclose(pFile);
    /*
    n = listWavData(data);//列出音频数据
    if(n)
    {
        printf("\nData size :%ld\n",n);
    }
    */
    bmp = makeRleBmpData(data,6000);//cacheBMP

    pFile = fopen("out.bmp", "wb");
	if (pFile != NULL)
	{
		puts("File open success\n");
	}
	else
	{
		return err(FileErr);
	}

    wirteBmpFile(bmp,pFile);//写入bmp文件
    fclose(pFile);

    delCacheWaveFile(data);
    delCache4bitBmp(bmp);
    data = NULL;
    bmp = NULL;
    pFile = NULL;
    return 0;
}